package com.example.quartztest.config;

import org.springframework.beans.factory.annotation.Value;

import javax.servlet.*;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author: zhaojie
 * @Date: Created in 17:19 2018/5/8
 * @Description:
 * @Modified By:
 */
public class AccessFilter extends HttpServlet implements Filter {
    /**
     * 序列ID，用来监测控制版本更新的
     */
    private static final long serialVersionUID = 1L;


    @Value("${yiyong.mavenspring.project.allow.url}")
    private String projectDemoAllowOriginUrl;

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        HttpServletResponse httpResponse = (HttpServletResponse) response;
        httpResponse.setHeader("Access-Control-Allow-Origin", projectDemoAllowOriginUrl);
        httpResponse.setHeader("Access-Control-Allow-Headers","Origin, X-Requested-With, Content-Type, Accept");
        httpResponse.setHeader("Access-Control-Allow-Credentials", "true");
        chain.doFilter(request, httpResponse);
    }
}
